package cn.exrick.xboot.modules.biddataproject.serviceimpl;

import cn.exrick.xboot.modules.bicmktbiddinginfo.entity.BidAndBidBack;
import cn.exrick.xboot.modules.biddataproject.entity.BidDataProtect;
import cn.exrick.xboot.modules.biddataproject.entity.BidDeptProvince;
import cn.exrick.xboot.modules.biddataproject.mapper.BidDataProtectMapper;
import cn.exrick.xboot.modules.biddataproject.mapper.BidDeptProvinceMapper;
import cn.exrick.xboot.modules.biddataproject.service.BidDeptProvinceService;
import cn.exrick.xboot.modules.biddataproject.service.IBidDataProtectService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 合同金额按部门省份分类
 * @author 王延超
 */
@Slf4j
@Service
@DS("other")
@Transactional
public class BidDeptProvinceServiceImpl extends ServiceImpl<BidDeptProvinceMapper, BidDeptProvince> implements BidDeptProvinceService {

    @Autowired
    private BidDeptProvinceMapper bidDeptProvinceMapper;

    /**
     * 合同金额按部门省份分类本年
     * @author 王延超
     */
    @Override
    public List<BidDeptProvince> getYearContractlnfo(Integer v){
        ;

        return bidDeptProvinceMapper.getYearContractlnfo(v);
    };

    /**
     * 合同金额按部门省份分类本年
     * @author 王延超
     */
    @Override
    public Map<String, Object> BidAndBidBackNumberAndMoneyByYear() {

        //获取有数据的所有省份
        String[] province = bidDeptProvinceMapper.getProvince();
        //获取有数据的所有单位
        String[] deptName = bidDeptProvinceMapper.getDeptName();
        List bidAndBidBacksa = new ArrayList<>();
        for (String s1 : deptName) {
            List<BidDeptProvince> bidAndBidBacks = new ArrayList<>();
            for (String s2 : province) {
                if (!s2.equals("")) {
                    BidDeptProvince dataByDeptNameAndProvince = bidDeptProvinceMapper.getDataByDeptNameAndProvince(s1, s2);
                    if (dataByDeptNameAndProvince != null) {
                        bidAndBidBacks.add(dataByDeptNameAndProvince);
                    } else {
                        bidAndBidBacks.add(new BidDeptProvince());
                    }
                }
            }
            bidAndBidBacksa.add(bidAndBidBacks);
            System.out.println(bidAndBidBacks.size());
        }
        Map<String, Object> map = new HashMap<>();
        map.put("buMendata", bidAndBidBacksa);
        map.put("shegFenData", province);
        map.put("bumen", deptName);
        System.out.println(map.size());
        return map;
    }

    /**
     * 合同金额按部门省份分类本月
     * @author 王延超
     */
    @Override
    public Map<String, Object> BidAndBidBackNumberAndMoneyByM() {

        //获取有数据的所有省份
        String[] province = bidDeptProvinceMapper.getProvinceM();
        //获取有数据的所有单位
        String[] deptName = bidDeptProvinceMapper.getDeptNameM();
        List bidAndBidBacksa = new ArrayList<>();
        for (String s1 : deptName) {
            List<BidDeptProvince> bidAndBidBacks = new ArrayList<>();
            for (String s2 : province) {
                if (!s2.equals("")) {
                    BidDeptProvince dataByDeptNameAndProvince = bidDeptProvinceMapper.getDataByDeptNameAndProvinceM(s1, s2);
                    if (dataByDeptNameAndProvince != null) {
                        bidAndBidBacks.add(dataByDeptNameAndProvince);
                    } else {
                        bidAndBidBacks.add(new BidDeptProvince());
                    }
                }
            }
            bidAndBidBacksa.add(bidAndBidBacks);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("buMendata", bidAndBidBacksa);
        map.put("shegFenData", province);
        map.put("bumen", deptName);
        return map;
    }
}
